package com.youyiwen.Service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youyiwen.Bean.Notice;
import com.youyiwen.Bean.User;
import com.youyiwen.Mapper.NoticeMapper;
import com.youyiwen.Mapper.UserMapper;
import com.youyiwen.Service.NoticeService;
import com.youyiwen.dto.NoticeDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: zhaoyang
 * @Date: 2021/04/06
 */
@Service
public class NoticeServiceImpl implements NoticeService {

    @Autowired
    private NoticeMapper noticeMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<NoticeDTO> showNotices(String userName) {
        List<NoticeDTO> list = new ArrayList<>();
        User user = userMapper.selectUserByName(userName);
        List<Notice> notices = noticeMapper.selectNotice(userName);
        for (Notice notice : notices) {
            NoticeDTO noticeDTO = new NoticeDTO();
            noticeDTO.setNotice(notice);
            noticeDTO.setUser(user);
            list.add(noticeDTO);
        }
        return list;
    }
}
